package com.inhim.pjhim.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.inhim.pjhim.R;
import com.inhim.pjhim.app.BaseActivity;
import com.inhim.pjhim.http.MyOkHttpClient;
import com.inhim.pjhim.http.Urls;
import com.inhim.pjhim.view.BToast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.HashMap;

import okhttp3.Request;

public class FeedBackActivity extends BaseActivity {
    private ImageView iv_back;
    private TextView tvCourse;
    private EditText ed_feed_back;
    private EditText ed_phone;
    private Button btn_submit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        initView();
    }

    @Override
    public Object offerLayout() {
        return R.layout.activity_feed_back;
    }

    @Override
    public void onBindView() {

    }

    @Override
    public void destory() {

    }

    private void initView() {
        iv_back = findViewById(R.id.iv_back);
        tvCourse = findViewById(R.id.tvCourse);
        ed_feed_back = findViewById(R.id.ed_feed_back);
        ed_phone = findViewById(R.id.ed_phone);
        btn_submit = findViewById(R.id.btn_submit);
        iv_back.setOnClickListener(v -> finish());
        btn_submit.setOnClickListener(v -> submit());
    }

    private void submit() {
        /*{
            "content": "string",
                "createTime": "2021-06-13T15:25:31.849Z",
                "intStatus": 0,
                "mobile": "string",
                "suggestId": 0,
                "updateTime": "2021-06-13T15:25:31.849Z",
                "vipUserId": 0
        }*/
        HashMap postMap = new HashMap();
        postMap.put("content", ed_feed_back.getText().toString());
        postMap.put("mobile", ed_phone.getText().toString());
        MyOkHttpClient myOkHttpClient = MyOkHttpClient.getInstance();
        myOkHttpClient.asyncJsonPost(Urls.minSuggestSave(), new HashMap(),
                new MyOkHttpClient.HttpCallBack() {
                    @Override
                    public void onError(Request request, IOException e) {
                    }

                    @Override
                    public void onSuccess(Request request, String result) {
                        hideLoading();
                        try {
                            JSONObject jsonObject = new JSONObject(result);
                            if (jsonObject.getInt("code") != 0) {
                                BToast.showText(jsonObject.getString("msg"), false);

                            } else {
                                BToast.showText("反馈成功", true);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                });
    }
}